package com.woniuxy.driverschool.controller;/* *
@author author
@create 2021-09-29 20:21
*/

import com.woniuxy.driverschool.entity.DriverPackage;
import com.woniuxy.driverschool.entity.ResponseResult;
import com.woniuxy.driverschool.service.DriverPackageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class DriverPackageController {

    @Autowired
    DriverPackageService driverPackageService;

    @GetMapping("/driverPackage")
    ResponseResult<List<DriverPackage>> getDriverPackage(DriverPackage driverPackage){
        ResponseResult<List<DriverPackage>> responseResult=new ResponseResult<List<DriverPackage>>();
        responseResult.setData(driverPackageService.getDriverPackage(driverPackage));
        responseResult.setMessage("获取全部时段成功");
        responseResult.setState(200);
        return responseResult;
    }

    @GetMapping("/driverPackage/{driverPackageId}")
    ResponseResult<DriverPackage> getDriverPackageById(@PathVariable("driverPackageId") int driverPackageId){
        ResponseResult<DriverPackage> responseResult=new ResponseResult<DriverPackage>();
        responseResult.setData(driverPackageService.getDriverPackageById(driverPackageId));
        responseResult.setMessage("获取全部时段成功");
        responseResult.setState(200);
        return responseResult;
    }

    @PostMapping("/driverPackage")
    ResponseResult addDriverPackage(@RequestBody DriverPackage driverPackage){
        driverPackage.setTotalPrice(driverPackage.getTrainCost()+driverPackage.getPlatformCost()
        +driverPackage.getCertificateCost()+driverPackage.getTestfirstCost()+driverPackage.getTestsecondCost()
        +driverPackage.getTestthirdCost()+driverPackage.getTestfourthCost());
        driverPackageService.addDriverPackage(driverPackage);
       ResponseResult responseResult=new ResponseResult();
       responseResult.setMessage("添加成功");
       responseResult.setState(200);
       return responseResult;
    }

    @PutMapping("/driverPackage")
    ResponseResult editDriverPackage(@RequestBody DriverPackage driverPackage){
        driverPackageService.modifyDriverPackage(driverPackage);
        ResponseResult responseResult=new ResponseResult();
        responseResult.setMessage("修改成功");
        responseResult.setState(200);
        return responseResult;
    }

    @DeleteMapping("/driverPackage/{packageId}")
    ResponseResult removeDriverPackage(@PathVariable("packageId") int packageId){
        System.out.println(packageId+"-------------");
        driverPackageService.removeDriverPackageById(packageId);
        ResponseResult responseResult=new ResponseResult();
        responseResult.setMessage("删除成功");
        responseResult.setState(200);
        return responseResult;
    }

}
